home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-18 | 49.1 KB | 1,751 lines | [TEXT/MPS ] |
- {*****************************************************************************
- #
- # Apple Macintosh Developer Technical Support
- #
- # Collection of Utilities for DTS Sample code
- #
- # Program: Utilities.p.o
- # File: Utilities.inc1.p - Pascal Implementation
- #
- # Copyright © 1988-1990 Apple Computer, Inc.
- # All rights reserved.
- #
- *****************************************************************************}
-
- {[j=20/53/1$] Pasmat Options}
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION CenteredAlert(alertID: INTEGER; relatedWindow:WindowPtr): INTEGER;
-
- { Given an alert ID and a window pointer the alert relates to, this function
- will center the alert’s rectangle before showing it on the proper screen.
- This follows the Apple Human Interface Guidelines for where to place a
- centered window on the screen. If the alert is not closely associated with
- another window, pass a NIL for the window pointer of the related window. If
- you pass a NIL, the alert is simply displayed where the resource
- would indicate. Note that if an error occurs when getting the resource for
- the alert, then the alert is not displayed, and the returned value is not
- the item hit, but is the error that occured when reading the resource. }
-
- VAR
- alertHandle: AlertTHndl;
- tempWindow: WindowPtr;
- alertRect: Rect;
- itemHit: INTEGER;
- hstate: SignedByte;
- err: OSErr;
-
- BEGIN
- alertHandle := AlertTHndl(GetAppResource('ALRT', alertID, err));
- itemHit := err;
-
- if (err = noErr) THEN BEGIN
- hstate := LockHandleHigh(Handle(alertHandle));
- { Do our part to help prevent fragmentation. }
-
- alertRect := alertHandle^^.boundsRect;
- { Preserve the real alert bounding rectangle. }
-
- tempWindow := NewWindow(NIL, alertRect, '', false, dBoxProc,
- WindowPtr(NIL), false, 0);
-
- if tempWindow <> NIL THEN BEGIN
- { Use an invisible temporary window to calculate where the alert will go. }
-
- alertHandle^^.boundsRect := CenterWindow(tempWindow, relatedWindow);
- DisposeWindow(tempWindow);
- END;
-
- itemHit := Alert(alertID, ModalFilterProcPtr(NIL));
- alertHandle^^.boundsRect := alertRect;
- { Restore the resource's bounding rect, so if this resource is ever used
- not through this function, it will open where the resource indicates. }
-
- HSetState(Handle(alertHandle), hstate);
- END;
-
- CenteredAlert := itemHit;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE CenterRectInRect(outerRect: Rect; VAR innerRect: Rect);
-
- { Given two rects, this function centers the second one within the first. }
-
- BEGIN
- PositionRectInRect(outerRect, innerRect, FixRatio (1, 2), FixRatio (1, 2));
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION CenterWindow(window:WindowPtr; relatedWindow:WindowPtr): Rect;
-
- { Center a window within a particular device. The device to center the window
- within is determined by passing a related window. This allows related
- windows to be kept on the same device. This is useful if an alert related
- to a specific window, for example. }
-
- VAR
- whichDevice: WindowPtr;
- deviceRect, oldWindowRect, newWindowRect, contentRect: Rect;
-
- BEGIN
- whichDevice := relatedWindow;
- if whichDevice = NIL THEN
- whichDevice := window;
- { If we have a window to center against, use the device for
- that window, else use the device for the window that is
- getting centered. }
-
- deviceRect := GetWindowDeviceRectNMB(whichDevice);
- { We now have the rectangle of the device we want to center within. }
-
- newWindowRect := GetWindowStructureRect(window);
- oldWindowRect := newWindowRect;
-
- PositionRectInRect(deviceRect, newWindowRect, FixRatio (1, 2), FixRatio (1, 3));
- { Figure out the new window strucRect so we can compare it against
- the old strucRect. This will tell us how much to move the window. }
-
- contentRect := GetWindowContentRect(window);
- { Get where the window is now. }
-
- OffsetRect(contentRect, newWindowRect.left - oldWindowRect.left,
- newWindowRect.top - oldWindowRect.top);
- { Calculate the new content rect. }
-
- MoveWindow(window, contentRect.left, contentRect.top, false);
- { Move the window to the new location. }
-
- CenterWindow := contentRect;
- END;
-
-
-
- {*****************************************************************************}
-
- {$S UtilMain}
- PROCEDURE CloseAnyWindow(window: WindowPtr);
-
- { Close a window. This handles desk accessory and application windows. Use
- this call (instead of DisposeAnyWindow) if the memory for the window was
- allocated by you. (Same as CloseWindow v.s. DisposeWindow.) }
-
- BEGIN
- IF IsDAWindow(window) THEN
- CloseDeskAcc(WindowPeek(window)^.windowKind)
- ELSE BEGIN
- IF IsAppWindow(window) THEN
- CloseWindow(window)
- ELSE
- IF WindowPeek(window)^.windowKind >= dialogKind THEN
- CloseDialog(DialogPtr(window));
- END;
- END;
-
-
-
- {*****************************************************************************}
-
- {$S UtilMain}
- PROCEDURE DisposeAnyWindow(window: WindowPtr);
-
- { Dispose a window. This handles desk accessory and application windows. Use
- this call (instead of CloseAnyWindow) if you want the memory for the window
- record to be disposed of. (Same as CloseWindow v.s. DisposeWindow.) }
-
- BEGIN
- IF IsDAWindow(window) THEN
- CloseDeskAcc(WindowPeek(window)^.windowKind)
- ELSE BEGIN
- IF IsAppWindow(window) THEN
- DisposeWindow(window)
- ELSE
- IF WindowPeek(window)^.windowKind >= dialogKind THEN
- DisposeDialog(DialogPtr(window));
- END;
- END;
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE DeathAlert(errResID: INTEGER; errStringIndex: INTEGER);
-
- { Display an alert that tells the user an error occurred, then exit the
- program. This routine is used as an ultimate bail-out for serious errors
- that prohibit the continuation of the application. Errors that do not
- require the termination of the application should be handled in a different
- manner. }
-
- BEGIN
- ErrorAlert(errResID, errStringIndex);
- ExitToShell;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE DeathAlertMessage(errResID, errStringIndex, message: INTEGER);
-
- { Display an alert that tells the user an error occurred, then exit the
- program. This routine is used as an ultimate bail-out for serious errors
- that prohibit the continuation of the application. Errors that do not
- require the termination of the application should be handled in a different
- manner. }
-
- BEGIN
- ErrorAlertMessage(errResID, errStringIndex, message);
- ExitToShell;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE ErrorAlert(errResID, errStringIndex: INTEGER);
-
- { Display an alert that tells the user an error occurred. }
-
- BEGIN
- ErrorAlertMessage(errResID, errStringIndex, 0);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S Main}
- PROCEDURE ErrorAlertMessage(errResID, errStringIndex, message: INTEGER);
-
- { Display an alert to inform the user of an error. errStringIndex acts as an
- index into a STR# resource of error messages. If no errStringIndex is given,
- i.e. = 0, then use a standard message. If message is not noErr then display
- it as well.
-
- BUG NOTE: GetIndString will return a bogus String if the index is not
- positive. }
-
- VAR
- msg1, msg2: Str255;
- itemHit: INTEGER;
-
- BEGIN
- SetCursor(qd.arrow);
-
- IF errStringIndex <= 0 THEN BEGIN
- errStringIndex := eStandardErr;
- errResID := rUtilStrings;
- END;
- GetIndString(msg1, errResID, errStringIndex);
-
- IF message = noErr THEN BEGIN
- ParamText(msg1, '', '', '');
- itemHit := CenteredAlert(rUtilErrorAlert, NIL);
- END
- ELSE BEGIN
- NumToString(message, msg2);
- ParamText(msg1, msg2, '', '');
- itemHit := CenteredAlert(rUtilErrorMessageAlert, NIL);
- END;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- FUNCTION FindSysFolder(VAR foundVRefNum:INTEGER; VAR foundDirID: LongInt): OSErr;
- { FindSysFolder returns the (real) vRefNum, and the DirID of the current
- system folder. It uses the Folder Manager if present, otherwise
- it falls back to SysEnvirons. It returns zero on success, otherwise
- a standard system error. }
-
- VAR
- gesResponse: LongInt;
- envRec: SysEnvRec;
- myWDPB: WDPBRec;
- volName: Str255;
- err: OSErr;
-
- BEGIN
- foundVRefNum := 0;
- foundDirID := 0;
- IF (Gestalt (gestaltFindFolderAttr, gesResponse) = noErr) &
- (BTst (gesResponse, gestaltFindFolderPresent)) THEN BEGIN { Does Folder Manager exist? }
- err := FindFolder (kOnSystemDisk, kSystemFolderType, kDontCreateFolder,
- foundVRefNum, foundDirID)
- END
- ELSE BEGIN
- { Gestalt can't give us the answer, so we resort to SysEnvirons }
- err := SysEnvirons (curSysEnvVers, envRec);
- IF err = noErr THEN BEGIN
- myWDPB.ioVRefNum := envRec.sysVRefNum;
- volName := ''; { Zero volume name }
- myWDPB.ioNamePtr := @volName;
- myWDPB.ioWDIndex := 0;
- myWDPB.ioWDProcID := 0;
- err := PBGetWDInfo (@myWDPB, FALSE);
- IF err = noErr THEN BEGIN
- foundVRefNum := myWDPB.ioWDVRefNum;
- foundDirID := myWDPB.ioWDDirID
- END
- END
- END;
-
- FindSysFolder := err
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetAppIndResource(theType: ResType;index: INTEGER; VAR err:OSErr): Handle;
-
- { GetAppIndResource gets a resource from the application's resource file by index }
- VAR
- savedResFile: INTEGER;
-
- BEGIN
- savedResFile := CurResFile;
- UseResFile (gAppResRef);
- GetAppIndResource := Get1IndResource (theType, index);
- err := ResError;
- UseResFile (savedResFile)
- END; { GetAppIndResource }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetAppNamedResource(theType: ResType;name: Str255; VAR err:OSErr): Handle;
-
- { GetAppNamedResource gets a resource from the application's resource file by name }
- VAR
- savedResFile: INTEGER;
-
- BEGIN
- savedResFile := CurResFile;
- UseResFile (gAppResRef);
- GetAppNamedResource := Get1NamedResource (theType, name);
- err := ResError;
- UseResFile (savedResFile)
- END; { GetAppNamedResource }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetAppResource(theType: ResType;theID: INTEGER; VAR err:OSErr): Handle;
-
- { GetAppResource gets a resource from the application's resource file by resource ID }
- VAR
- savedResFile: INTEGER;
-
- BEGIN
- savedResFile := CurResFile;
- UseResFile (gAppResRef);
- GetAppResource := Get1Resource (theType, theID);
- err := ResError;
- UseResFile (savedResFile)
- END; { GetAppResource }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetAUXVersion: INTEGER;
-
- { GetAUXVersion -- Checks for the presence of A/UX by whatever means is appropriate.
- Returns the major version number of A/UX (i.e. 0 if A/UX is not present, 1 for
- any 1.x.x version 2 for any 2.x version, etc.
-
- This code should work for all past, present and future A/UX systems. }
-
- CONST
- kHWCfgFlags = $B22; {low memory hardware config flags}
- kAUXbit = 9; {bit set in kHWCfgFlags for A/UX}
- kShiftHighByte = 8; {shift 8 bits to the right}
- kAUXnotRunning = 0; {not running A/UX}
- kDefaultVersion = $100; {assumed version 1.x.x of A/UX}
-
- VAR
- AUXversion: LONGINT;
- err: INTEGER;
-
- BEGIN
- err:= noErr;
- AUXversion:= kAUXnotRunning; {assume A/UX is not running}
- err:= Gestalt(gestaltAUXVersion, AUXVersion);
-
- IF (err = gestaltUnknownErr) | (err = gestaltUndefSelectorErr) THEN BEGIN
- IF BTst(IntegerPtr(kHWCfgFlags)^, kAUXbit) THEN
- AUXversion:= kDefaultVersion; {A/UX is running, default version}
- END;
- GetAUXVersion:= BSR(AUXversion, kShiftHighByte);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetCenteredDialog(id:INTEGER; storage: Ptr;
- relWindow, behind:WindowPtr): DialogPtr;
-
- { Given a dialog ID and a window pointer the dialog relates to, this function
- will center the dialog’s rectangle before showing it on the proper screen.
- This follows the Apple Human Interface Guidelines for where to place a
- centered window on the screen. If the dialog is not closely associated with
- another window, pass a nil for the window pointer of the related window. If
- you pass a nil, the dialog is simply displayed where the resource
- would indicate. }
-
- VAR
- dlogResource: DialogTHndl;
- dialog: DialogPtr;
- oldVis: BOOLEAN;
- hstate: SignedByte;
- err: OSErr;
- dummyRect: Rect;
-
- BEGIN
- dialog := NIL;
- dlogResource := DialogTHndl(GetAppResource('DLOG', id, err));
- if (dlogResource <> NIL) THEN BEGIN
- hstate := LockHandleHigh(Handle(dlogResource));
- oldVis := dlogResource^^.visible;
- dlogResource^^.visible := false;
- dialog := GetNewDialog(id, storage, behind);
- if dialog <> NIL THEN BEGIN
- dummyRect := CenterWindow(dialog, relWindow);
- if oldVis = true THEN
- ShowWindow(dialog);
- END;
- dlogResource^^.visible := oldVis;
- HSetState(Handle(dlogResource), hstate);
- END;
- GetCenteredDialog := dialog;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetCenteredWindow(id:INTEGER; storage: Ptr; relWindow, behind: WindowPtr;
- inColor:BOOLEAN): WindowPtr;
-
- { Given a window ID and a window pointer the window relates to, this function
- will center the window’s rectangle before showing it on the proper screen.
- This follows the Apple Human Interface Guidelines for where to place a
- centered window on the screen. If the window is not closely associated with
- another window, pass a nil for the window pointer of the related window. If
- you pass a nil, the window is simply displayed where the resource
- would indicate. }
-
- BEGIN
- GetCenteredWindow := GetSomeKindOfWindow(CenterWindow, id, storage, relWindow,
- behind, inColor);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetCheckOrRadio(dlgPtr: DialogPtr; itemNo: INTEGER): BOOLEAN;
-
- VAR
- iKind: INTEGER;
- iHandle: Handle;
- iRect: Rect;
-
- BEGIN
- GetDialogItem(dlgPtr, itemNo, iKind, iHandle, iRect);
- GetCheckOrRadio := GetControlValue(ControlHandle(iHandle)) <> 0;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetGestaltResult (gestaltSelector: OSType): LongInt;
-
- { GetGestaltResult returns the result value from Gestalt for the specified selector.
- If Gestalt returned an error GetGestaltResult returns zero. Use of this function
- is only cool if we don't care whether Gestalt returned an error. In many cases
- you may need to know the exact Gestalt error code so then this routine would be
- inappropriate. See GetAUXVersion for example.}
-
- VAR
- gestaltResult: LongInt;
-
- BEGIN
- IF Gestalt (gestaltSelector, gestaltResult) = noErr THEN
- GetGestaltResult := gestaltResult
- ELSE
- GetGestaltResult := 0
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetGlobalMouse: Point;
-
- { Get the global coordinates of the mouse. When you call OSEventAvail it will
- return either a pending event or a null event. In either case, the where
- field of the event record will contain the current position of the mouse in
- global coordinates and the modifiers field will reflect the current state of
- the modifiers. Another way to get the global coordinates is to call GetMouse
- and LocalToGlobal, but that requires being sure that thePort is set to a
- valid port. }
-
- CONST
- kNoEvents = 0;
-
- VAR
- event: EventRecord;
-
- BEGIN
- IF OSEventAvail(kNoEvents, event) THEN; { we aren’t interested in any events }
- GetGlobalMouse := event.where; { just the mouse position }
- END; { GetGlobalMouse }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetGlobalTopLeft(window: WindowPtr): Point;
-
- { Given a window, this will return the top left point of the window’s port in
- global coordinates. Something this doesn’t include is the window’s drag
- region (or title bar). This returns the top left point of the window’s
- content area only. }
-
- VAR
- oldPort: GrafPtr;
- globalPt: Point;
-
- BEGIN
- GetPort(oldPort);
- SetPort(window);
- globalPt := window^.portRect.topLeft;
- LocalToGlobal(globalPt);
- SetPort(oldPort);
- GetGlobalTopLeft := globalPt;
- END; { GetGlobalTopLeft }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetKFreeSpace(vRefNum: INTEGER): LONGINT;
-
- { Return the amount of free space on the volume in KBytes. This builds a
- LONGINT based on an unsigned INTEGER, which looks like a negitive value to
- Pascal. -1 is return as the size if there is an error. }
-
- VAR
- pb: HParamBlockRec;
- convert: TwoIntsMakesALong;
- err: OSErr;
-
- BEGIN
- WITH pb DO BEGIN { set up the block for PBHGetVInfo }
- ioNamePtr := NIL; { we don't care about the name }
- ioVRefNum := vRefNum;
- ioVolIndex := 0; { use ioVRefNum only }
- END; { with }
- err := PBHGetVInfo(@pb, FALSE);
-
- IF (err = noErr) THEN BEGIN
- convert.ints[0] := 0;
- convert.ints[1] := pb.ioVFrBlk;
- GetKFreeSpace := (convert.long * pb.ioVAlBlkSiz) DIV 1024;
- END
- ELSE { we couldn't get free space size! }
- GetKFreeSpace := - 1;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetMainScreenRect: Rect;
-
- VAR
- mainDevice: GDHandle;
- mainPort: GrafPtr;
-
- BEGIN
- IF gQDVersion > kQDOriginal THEN BEGIN
- mainDevice := GetMainDevice;
- GetMainScreenRect := mainDevice^^.gdRect;
- END
- ELSE BEGIN
- GetWMgrPort(mainPort);
- GetMainScreenRect := mainPort^.portRect;
- END;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetRectDevice(globalRect: Rect): GDHandle;
-
- { Find the greatest overlap device for the given global rectangle. }
-
- VAR
- area: LONGINT;
- maxArea: LONGINT;
- device: GDHandle;
- intersection: Rect;
-
- BEGIN {GetRectDevice}
- GetRectDevice := GetMainDevice; { Use as default choice. }
- maxArea := 0;
-
- device := GetDeviceList;
- WHILE device <> NIL DO BEGIN
- IF TestDeviceAttribute(device, screenDevice) & TestDeviceAttribute(device,
- screenActive) & SectRect(globalRect, device^^.gdRect, intersection) THEN BEGIN
- WITH intersection DO
- area := LONGINT(right - left) * LONGINT(bottom - top);
- IF area > maxArea THEN BEGIN
- GetRectDevice := device;
- maxArea := area;
- END; {IF area > maxArea}
- END; {IF TestDeviceAttribute…}
- device := GetNextDevice(device);
- END; {WHILE device <> NIL}
- END; {GetRectDevice}
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetRectDeviceRect(globalRect: Rect): Rect;
-
- { Find the rect of the greatest overlap device for the given global rect. }
-
- VAR
- device: GDHandle;
-
- BEGIN
- IF gQDVersion > kQDOriginal THEN BEGIN
- device := GetRectDevice(globalRect);
- GetRectDeviceRect := device^^.gdRect;
- END
- ELSE
- GetRectDeviceRect := GetMainScreenRect;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- FUNCTION GetSomeKindOfWindow(FUNCTION whatKind(window, relWindow:WindowPtr):Rect;
- windID:INTEGER; storage: Ptr; relWindow, behind:WindowPtr; inColor:BOOLEAN):WindowPtr;
-
- { Given a window positioning procedure pointer, a window ID and a window
- pointer the window relates to, this function open a new window by either
- a NewCWindow or a NewWindow call, depending on the value of inColor. The
- window will be opened invisible, independent of what the resource says.
- Once the window is opened successfully, the positioning procedure is
- called. The positioning procedure is passed a pointer to the just-opened
- invisible window and a pointer to the related window. It is up to the
- positioning procedure to move the invisible window to the correct location
- on the correct device. Once the positioning procedure returns, the window
- will be made visible if so indicated by the resource. }
-
- VAR
- windowResource: WindowTHndl;
- wt: WindowTemplate;
- aWindow: WindowPtr;
- err: OSErr;
- dummyRect: Rect;
-
- BEGIN
- if gQDVersion = kQDOriginal THEN
- inColor := false;
-
- aWindow := nil; { Assume we will fail. (Good attitude.) }
- if storage = NIL THEN
- storage := Ptr(NewPtr(sizeof(WindowRecord)));
-
- if storage <> NIL THEN BEGIN
- { If we can allocate the memory for the window record... }
-
- windowResource := WindowTHndl(GetAppResource('WIND', windID, err));
- if windowResource <> NIL THEN BEGIN
- { If we can load the window resource... }
-
- wt := windowResource^^; { Make local copy of resource. }
-
- if inColor = true THEN { Open either a regular or color window. }
- aWindow := NewCWindow(storage, wt.boundsRect, wt.title, false,
- wt.procID, behind, wt.goAwayFlag, wt.refCon)
- ELSE
- aWindow := NewWindow(storage, wt.boundsRect, wt.title, false,
- wt.procID, behind, wt.goAwayFlag, wt.refCon);
-
- if aWindow <> NIL THEN BEGIN { If we were able to open a window... }
- dummyRect := whatKind(aWindow, relWindow);
- { Call the designated window positioning procedure. }
-
- if wt.visible THEN
- ShowWindow(aWindow);
- { If resource says window should be visible, do it. }
- END;
- END;
- if aWindow = NIL THEN
- DisposePtr(Ptr(storage));
- { If we failed, then get rid of window record memory. }
- END;
-
- GetSomeKindOfWindow := aWindow;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- FUNCTION GetStaggeredWindow(id:INTEGER; storage: Ptr;
- relWindow,behind:WindowPtr; inColor:BOOLEAN):WindowPtr;
-
- { Given a window ID and a window pointer the window relates to, this function
- will stagger the window’s rectangle before showing it on the proper screen.
- This follows the Apple Human Interface Guidelines for where to place a
- staggered window on the screen. If the window is not closely associated
- with another window, pass a nil for the window pointer of the related
- window. If you pass a nil, the window is simply displayed where the
- resource would indicate. }
-
- BEGIN
- GetStaggeredWindow := GetSomeKindOfWindow(StaggerWindow, id, storage, relWindow, behind, inColor);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- FUNCTION GetTrapType(theTrap: INTEGER): TrapType;
-
- { Determines the type of a trap based on its trap number. If bit 11 is clear,
- then it is an OS trap. Otherwise, it is a Toolbox trap. }
-
- BEGIN
- { OS traps start with A0, Tool with A8 or AA. }
- IF BAND(theTrap, $0800) = 0 THEN { per D.A }
- GetTrapType := OSTrap
- ELSE
- GetTrapType := ToolTrap;
- END; { GetTrapType }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- FUNCTION GetWindowContentRect(window:WindowPtr):Rect;
-
- { Given a window pointer, return the global rectangle that encloses the
- content area of the window. }
-
- VAR
- oldPort: WindowPtr;
- contentRect: Rect;
-
- BEGIN
- GetPort(oldPort);
- SetPort(window);
- contentRect := window^.portRect;
- LocalToGlobalRect(contentRect);
- SetPort(oldPort);
- GetWindowContentRect := contentRect;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetWindowCount(includeDAs,includeInvisibles:BOOLEAN):INTEGER;
-
- { This procedure counts the number of windows in the application plane.
- You have the choices of also including DAs and invisible windows in
- this count. }
-
- VAR
- window: WindowPeek;
- count: INTEGER;
-
- BEGIN
- count := 0;
- window := WindowPeekPtr(LMGetWindowList)^;
-
- WHILE window <> NIL DO BEGIN
-
- if (window^.windowKind < 0) and (includeDAs = false) THEN
- ELSE
- if (window^.visible = true) and (includeInvisibles = true) THEN
- count := count + 1;
-
- window := window^.nextWindow;
- END;
-
- GetWindowCount := count;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetWindowDevice(window:WindowPtr):GDHandle;
-
- { Find the greatest overlap device for the given window. }
-
- BEGIN
- GetWindowDevice := GetRectDevice(GetWindowStructureRect(window));
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetWindowDeviceRect(window:WindowPtr):Rect;
-
- { Given a window pointer, find the device that contains most of the window
- and return the device's bounding rectangle. }
-
- BEGIN
- if gQDVersion > kQDOriginal THEN
- GetWindowDeviceRect := GetWindowDevice(window)^^.gdRect
- ELSE
- GetWindowDeviceRect := GetMainScreenRect;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetWindowDeviceRectNMB(window:WindowPtr):Rect;
-
- { Given a window pointer, find the device that contains most of the window
- and return the device's bounding rectangle. If this device is the main
- device, then remove the menubar area from the rectangle. }
-
- VAR
- deviceRect, tempRect: Rect;
-
- BEGIN
- deviceRect := GetWindowDeviceRect(window);
- tempRect := GetMainScreenRect;
- if (EqualRect(deviceRect, tempRect) = true) THEN
- deviceRect.top := deviceRect.top + GetMBarHeight;
-
- GetWindowDeviceRectNMB := deviceRect;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION GetWindowStructureRect(window:WindowPtr):Rect;
-
- { This procedure is used to get the rectangle that surrounds the entire
- structure of a window. This is true whether or not the window is visible.
- If the window is visible, then it is a simple matter of using the bounding
- rectangle of the structure region. If the window is invisible, then the
- strucRgn is not correct. To make it correct, then window has to be moved
- way off the screen and then made visible. This generates a valid strucRgn,
- although it is valid for the position that is way off the screen. It still
- needs to be offset back into the original position. Once the bounding
- rectangle for the strucRgn is obtained, the window can then be hidden again
- and moved back to its correct location. Note that ShowHide is used,
- instead of ShowWindow and HideWindow. HideWindow can change the plane of
- the window. Also, ShowHide does not affect the hiliting of windows. }
-
- VAR
- oldPort: GrafPtr;
- structureRect: Rect;
- windowLoc: Point;
-
- BEGIN
- if WindowPeek(window)^.visible = true THEN
- structureRect := WindowPeek(window)^.strucRgn^^.rgnBBox
- ELSE BEGIN
- GetPort(oldPort);
- SetPort(window);
- windowLoc := GetGlobalTopLeft(window);
- MoveWindow(window, windowLoc.h, kOffscreenLoc, false);
- ShowHide(window, true);
- structureRect := WindowPeek(window)^.strucRgn^^.rgnBBox;
- ShowHide(window, false);
- MoveWindow(window, windowLoc.h, windowLoc.v, false);
- SetPort(oldPort);
- OffsetRect(structureRect, 0, windowLoc.v - kOffscreenLoc);
- END;
-
- GetWindowStructureRect := structureRect;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE GlobalToLocalRect(VAR aRect: Rect);
-
- BEGIN
- GlobalToLocal(aRect.topLeft);
- GlobalToLocal(aRect.botRight);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- PROCEDURE InitToolBox;
-
- BEGIN
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- PROCEDURE InitUtilities;
-
- { InitUtilities sets up some global variables for use by the utilities package. If you call
- StandardInitialization, you don't need to call this, as it will do it for you. }
-
- TYPE
- OSTypePtr = ^OSType;
-
- VAR
- apParam: Handle;
- bndlResource: Handle;
- err: OSErr;
-
- BEGIN
- gUtilitiesInited := FALSE;
-
- { Init all the Gestalt variables }
- gMachineType := GetGestaltResult (gestaltMachineType);
- gSystemVersion := GetGestaltResult (gestaltSystemVersion);
- gProcessorType := GetGestaltResult (gestaltProcessorType);
-
- { We only concern ourselves with there being an FPU, not which type it is }
- gHasFPU := (GetGestaltResult (gestaltFPUType) <> gestaltNoFPU);
-
- { We only concern ourselves with the major QD version number
- 0 for original QD, 1 for 8-bit color QD, and 2 for 32-bit QD }
- gQDVersion := BAND ((BSR (GetGestaltResult (gestaltQuickdrawVersion), 8)), $FF);
- gKeyboardType := GetGestaltResult (gestaltKeyboardType);
- gAppleTalkVersion := GetGestaltResult (gestaltAppleTalkVersion);
-
- { We only concern ourselves with there being an PMMU, not which type it is }
- gHasPMMU := (GetGestaltResult (gestaltMMUType) >= gestalt68851);
- gAUXVersion := getAUXVersion;
-
- gHasWaitNextEvent := TrapExists(_WaitNextEvent);
- gInBackground := FALSE;
-
- GetAppParms(gAppName, gAppResRef, apParam);
-
- bndlResource := GetAppIndResource('BNDL', 1, err);
- IF (bndlResource <> NIL) THEN
- gSignature := OSTypePtr(bndlResource^)^
- ELSE
- gSignature := '????';
-
- gUtilitiesInited := TRUE;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION IsAppWindow(window: WindowPtr): BOOLEAN;
-
- { Check to see if a window belongs to the application. If the window pointer
- passed was NIL, then it could not be an application window. WindowKinds that
- are negative belong to the system and windowKinds less than userKind are
- reserved by Apple except for windowKinds equal to dialogKind, which mean it
- is a dialog. }
-
- BEGIN
- IF window = NIL THEN
- IsAppWindow := FALSE
- ELSE
- IsAppWindow := (WindowPeek(window)^.windowKind >= userKind);
- END; { IsAppWindow }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION IsDAWindow(window: WindowPtr): BOOLEAN;
-
- { Check if a window belongs to a desk accessory. This will first test for a
- NIL window. DAs will have a negative windowKind. }
-
- BEGIN
- IF window = NIL THEN
- IsDAWindow := FALSE
- ELSE { DA windows have negative windowKinds }
- IsDAWindow := (WindowPeek(window)^.windowKind < 0);
- END; { IsDAWindow }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE LocalToGlobalRect(VAR aRect: Rect);
-
- BEGIN
- LocalToGlobal(aRect.topLeft);
- LocalToGlobal(aRect.botRight);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION LockHandleHigh(theHandle: UNIV Handle):SignedByte;
-
- BEGIN
- LockHandleHigh := HGetState(theHandle);
- MoveHHi(theHandle);
- HLock(theHandle);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- FUNCTION NumToolboxTraps: INTEGER;
-
- { InitGraf is always implemented (trap $A86E). If the trap table is big
- enough, trap $AA6E will always point to either Unimplemented or some other
- trap, but will never be the same as InitGraf. Thus, you can check the size
- of the trap table by asking if the address of trap $A86E is the same as
- $AA6E. }
-
- BEGIN
- IF NGetTrapAddress(_InitGraf, ToolTrap) = NGetTrapAddress($AA6E, ToolTrap) THEN
- NumToolboxTraps := $200
- ELSE
- NumToolboxTraps := $400;
- END; { NumToolboxTraps }
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE OutlineControl(button: UNIV ControlHandle);
-
- {Given any control handle, this will draw an outline around it. This is
- used for the default button of a window. The extra nice feature here is
- that I’ll erase the outline for buttons that are inactive. Seems like
- there should be a Toolbox call for getting a control’s hilite state.
- Since there isn’t, I have to look into the control record myself. This
- should be called for update and activate events.
-
- The method for determining the oval diameters for the roundrect is a
- little different than that recommended by Inside Mac. IM I-407 suggests
- that you use a hardcoded (16,16) for the diameters. However, this only
- looks good for small roundrects. For larger ones, the outline doesn’t
- follow the inner roundrect because the CDEF for simply buttons doesn’t
- use (16,16). Instead, it uses half the height of the button as the
- diameter. By using this formula, too, our outlines look better.
-
- WARNING: This will set the current port to the control’s window.}
-
- VAR
- theRect: Rect;
- curPen: PenState;
- buttonOval: INTEGER;
-
- BEGIN
- IF button <> NIL THEN BEGIN
- SetPort(button^^.contrlOwner);
- GetPenState(curPen);
- PenNormal;
- theRect := button^^.contrlRect;
- InsetRect(theRect, kButtonFrameInset, kButtonFrameInset);
- buttonOval := ((theRect.bottom - theRect.top) DIV 2) + 2;
- IF (button^^.contrlHilite = kCntlActivate) THEN
- PenPat(qd.black)
- ELSE
- PenPat(qd.gray);
- PenSize(kButtonFrameSize, kButtonFrameSize);
- FrameRoundRect(theRect, buttonOval, buttonOval);
- SetPenState(curPen);
- END;
- END;
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE OutlineDialogItem(dlgPtr: DialogPtr; item: INTEGER);
-
- VAR
- iKind: INTEGER;
- iHandle: Handle;
- iRect: Rect;
-
- BEGIN
- GetDialogItem(dlgPtr, item, iKind, iHandle, iRect);
- OutlineControl(iHandle);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE PositionRectInRect(outerRect: Rect; VAR innerRect: Rect; horzRatio, vertRatio: Fixed);
-
- { Given two rectangles, this routine positions the second within the first one
- so that the it maintains the spacing specified by the horzRatio and vertRatio
- parameters. In other words, to center an inner rectangle hoizontally, but
- have its center be 1/3 from the top of the outer rectangle, call this
- routine with horzRatio = FixRatio (1, 2), vertRatio = FixRatio (1, 3). We use
- Fixed rather than floating point to avoid complications when mixing MC68881/non-MC68881
- versions of Utilities. }
-
- VAR
- outerRectHeight: INTEGER;
- outerRectWidth: INTEGER;
- innerRectHeight: INTEGER;
- innerRectWidth: INTEGER;
- yLocation: INTEGER;
- xLocation: INTEGER;
-
- BEGIN
- outerRectHeight := outerRect.bottom - outerRect.top;
- outerRectWidth := outerRect.right - outerRect.left;
-
- innerRectHeight := innerRect.bottom - innerRect.top;
- innerRectWidth := innerRect.right - innerRect.left;
-
- yLocation := Fix2Long (FixMul (Long2Fix (outerRectHeight - innerRectHeight), vertRatio))
- + outerRect.top;
- xLocation := Fix2Long (FixMul (Long2Fix (outerRectWidth - innerRectWidth), horzRatio))
- + outerRect.left;
- WITH innerRect DO BEGIN
- top := yLocation;
- left := xLocation;
- bottom := yLocation + innerRectHeight;
- right := xLocation + innerRectWidth;
- END;
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- PROCEDURE PullApplicationToFront;
-
- CONST
- kBroughtToFront = 3;
-
- VAR
- count: INTEGER;
- event: EventRecord;
- ignoreResult: BOOLEAN;
-
- BEGIN
- { This code is necessary to pull the application into the foreground. I use
- EventAvail because I don’t want to remove any events the user may have done,
- such as typing ahead. Until the application has made a few calls (3 seems
- to be the magic number) to the Event Manager, MultiFinder keeps me in the
- background. Splashscreens and Alerts will remain in a background layer
- until we get a few events. This is documented in Tech Note #180.}
-
- FOR count := 1 TO kBroughtToFront DO
- ignoreResult := EventAvail(everyEvent, event);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE SelectButton(button: UNIV ControlHandle);
-
- { Given the button control handle, this will cause the button to look as if it
- has been clicked in. This is nice to do for the user if they type return or
- enter to select the default item.}
-
- VAR
- finalTicks: LONGINT;
-
- BEGIN
- HiliteControl(button, kSelect);
- Delay(kDelayTime, finalTicks);
- HiliteControl(button, kDeselect);
- END; { SelectButton }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE SetCheckOrRadioButton(dlgPtr: DialogPtr; itemNo: INTEGER; state: INTEGER);
-
- { Handy routine for setting the value of a radio button. Given a dialog
- pointer, and item number, and a state, this routine will take care of the
- rest. }
-
- VAR
- iKind: INTEGER;
- iHandle: Handle;
- iRect: Rect;
-
- BEGIN
- GetDialogItem(dlgPtr, itemNo, iKind, iHandle, iRect);
- SetControlValue(ControlHandle(iHandle), state);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- FUNCTION StaggerWindow(window,relatedWindow:WindowPtr):Rect;
-
- { This algorithm for staggering windows does quite a good job. It also is
- quite gnarly. Here's the deal:
- There are pre-designated positions that we will try when positioning a
- window. These slots will be tried from the upper-left corner towards the
- lower-right corner. If there are other windows in that slot, then we will
- consider that slot taken, and proceed to the next slot. A slot is
- determined to be taken by checking a point with a slop area. This slop
- area is diamond-shaped, not simply rectangular. If there is no other
- visible window with an upper-left corner within the slopt diamond, then
- we are allowed to position our window there.
- The above rule holds true unless this forces the window to be partly
- off the screen. If the window ends up partly off the screen, then we try
- a new diagonal just below the first diagonal we tried. We keep trying
- lower and lower diagonals until we find a spot for the window, or the
- diagonal doesn't fit on the screen at all. If the diagonal doesn't fit,
- then we try diagonals to the right of the first diagonal. If even this
- doesn't work, then we give up and put the window in the original spot
- we tried. }
-
- VAR
- whichDevice: WindowPtr;
- deviceRect, oldWindowRect, newWindowRect,
- slot1, contentRect: Rect;
- contained, finis: BOOLEAN;
- vertDirection, dummyBoolean: BOOLEAN;
- diamondSize, diagNum, slotNum: INTEGER;
-
- { WalkDiagonal traverses an imaginary line which is roughly diagonal starting at
- a point determined by diagNum. It checks successive slots along that line for
- a slot (who's size is determined by diamondSize) which is not occupied by a
- window. It returns true if it successfully finds such a slot. foundWindowRect
- is set to the appropriate slot. }
- FUNCTION WalkDiagonal (VAR foundWindowRect: Rect; destDeviceRect:Rect;
- diamondSize, diagNum: INTEGER; VAR slotNum: INTEGER): BOOLEAN;
- VAR
- done, junk: BOOLEAN;
- testRect: Rect;
- windowToStaggerFrom: WindowPtr;
-
- { WindowNotInSlot returns true if there is no window occupying the slot indicated
- by foundWindowRect. }
- FUNCTION WindowNotInSlot (VAR foundWindowRect: Rect;
- windowToStaggerFrom: WindowPtr): BOOLEAN;
- VAR
- delta, absdelta: Point;
- testRect, staggerFromRect: Rect;
- BEGIN { WindowNotInSlot }
- WindowNotInSlot := true;
-
- if WindowPeek(windowToStaggerFrom)^.visible = true then BEGIN
- { This window is not invisible. Staggering from an invisible
- window is going to confuse the user, so don't do it. }
-
- staggerFromRect := GetWindowStructureRect(windowToStaggerFrom);
- delta.v := staggerFromRect.top - newWindowRect.top;
- delta.h := staggerFromRect.left - newWindowRect.left;
- absdelta := delta;
- IF delta.v < 0 THEN
- absdelta.v := -delta.v;
- IF delta.h < 0 THEN
- absdelta.h := -delta.h;
- IF absdelta.h + absdelta.v < diamondSize THEN BEGIN
- IF delta.h + delta.v > 0 THEN
- OffsetRect(foundWindowRect, delta.h, delta.v);
- { If the window that took our slot is closer to
- the lower-right corner than we are, then use
- this window's location as the basis for the
- slots from now on. This will align new windows
- with previous windows that are not gridded to
- the default slot positions. The check for > 0
- is necessary to prevent bouncing between two
- existing windows. This check guarantees that
- we are progressing with the evaluation. }
- WindowNotInSlot := false;
- END;
- END; { if window is visible }
- END; { WindowNotInSlot }
-
- BEGIN { WalkDiagonal }
- slotNum := 0;
- done := false;
- WalkDiagonal := true;
- while NOT done DO BEGIN
- junk := SectRect (foundWindowRect, destDeviceRect, testRect);
- { We are done if the window is not entirely on destination device }
- done := NOT EqualRect (foundWindowRect, testRect);
- if NOT done THEN BEGIN
- windowToStaggerFrom := FrontWindow;
- { Loop through all windows and see if any of them occupy our slot }
- while (windowToStaggerFrom <> NIL) &
- WindowNotInSlot (foundWindowRect, windowToStaggerFrom) DO
- windowToStaggerFrom :=
- WindowPtr (WindowPeek (windowToStaggerFrom)^.nextWindow);
- { If windowToStaggerFrom is now NIL, then we tried all the windows
- in this slot and none of them occupied it, so this slot is available. }
- if windowToStaggerFrom = NIL THEN
- done := true
- ELSE BEGIN
- { Try next slot }
- slotNum := slotNum + 1;
- OffsetRect (foundWindowRect, kStaggerH, kStaggerV);
- END
- END ELSE
- WalkDiagonal := false;
- END
- END; { WalkDiagonal }
-
- BEGIN { StaggerWindow }
- { If we have a window to stagger from, use the device for that window,
- else use the device for the window that is getting staggered. }
- IF relatedWindow = NIL THEN
- whichDevice := window
- ELSE
- whichDevice := relatedWindow;
-
- deviceRect := GetWindowDeviceRectNMB(whichDevice);
- { We now have the rect of the device we want to stagger within. }
-
- oldWindowRect := GetWindowStructureRect(window);
- newWindowRect.top := deviceRect.top + kStartPtV;
- newWindowRect.left := deviceRect.left + kStartPtH;
- newWindowRect.bottom := newWindowRect.top + oldWindowRect.bottom - oldWindowRect.top;
- newWindowRect.right := newWindowRect.left + oldWindowRect.right - oldWindowRect.left;
- { We now have a new rect for the first window position slot. }
-
- slot1 := newWindowRect;
- { We keep this slot in case we find no acceptable slots. If we
- don't find an acceptable one, we will use this one anyway. }
-
- if kStaggerH < kStaggerV THEN
- diamondSize := kStaggerH
- ELSE
- diamondSize := kStaggerV;
-
- finis := false;
- vertDirection := true;
- WHILE NOT finis DO BEGIN
- finis := WalkDiagonal (newWindowRect, deviceRect, diamondSize, diagNum, slotNum);
- if NOT finis THEN BEGIN
- newWindowRect := slot1; { Reset newWindowRect }
- if slotNum = 0 THEN BEGIN
- if vertDirection THEN BEGIN
- vertDirection := false;
- diagNum := 0; { Reset diagonal number }
- END
- ELSE
- finis := true; { Out of possible slots }
- END;
- diagNum := diagNum + 1;
- if NOT finis THEN
- if vertDirection THEN
- OffsetRect(newWindowRect, 0, diagNum * kStaggerV)
- ELSE
- OffsetRect(newWindowRect, diagNum * kStaggerH, 0);
- END
- END;
-
- contentRect := GetWindowContentRect(window);
- { Get where the window is now. }
-
- OffsetRect(contentRect, newWindowRect.left - oldWindowRect.left,
- newWindowRect.top - oldWindowRect.top);
- { Calculate the new content rect. }
-
- MoveWindow(window, contentRect.left, contentRect.top, false);
- { Move the window to the new location. }
-
-
- StaggerWindow := contentRect;
- END; { StaggerWindow }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE StandardAbout(appNameStringID: INTEGER);
-
- VAR
- apNameHndl: StringHandle;
- curVersion: VersRecHndl;
- apName: Str255;
- verNum: Str255;
- itemHit: INTEGER;
- err: OSErr;
-
- BEGIN
- IF NOT gUtilitiesInited THEN { make sure we were inititialized }
- InitUtilities;
-
- apNameHndl := NIL;
- IF (appNameStringID <> kUseRealAppName) THEN BEGIN
- IF (appNameStringID <> kUseCreatorString) THEN
- apNameHndl := GetString(appNameStringID);
- IF (apNameHndl = NIL) THEN
- apNameHndl := StringHandle(GetAppResource(gSignature, 0, err));
- END;
-
- IF (apNameHndl = NIL) | (appNameStringID = kUseRealAppName) THEN
- apName := gAppName
- ELSE
- apName := apNameHndl^^;
-
- curVersion := VersRecHndl(GetAppResource('vers', 1, err));
- IF curVersion <> NIL THEN BEGIN
- verNum := StringPtr(ORD(@curVersion^^.shortVersion) + ORD(curVersion^^.
- shortVersion[0]) + 1)^ { get long version string }
- END
- ELSE
- verNum := '????'; { at least initialize it }
-
- ParamText(apName, verNum, '', '');
-
- itemHit := CenteredAlert(rStdAboutAlert, NIL);
- END; { StandardAbout }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- PROCEDURE StandardInitialization(callsToMoreMasters: INTEGER);
-
- VAR
- count: INTEGER;
-
- BEGIN
- InitToolBox;
-
- IF callsToMoreMasters > 0 THEN
- FOR count := 1 TO callsToMoreMasters DO { allocate master pointer blocks }
- MoreMasters;
-
- PullApplicationToFront;
-
- InitUtilities;
-
- END; { StandardInitialization }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- PROCEDURE StandardMenuSetup(MBARID, AppleMenuID: INTEGER);
-
- VAR
- menuBar: Handle;
-
- BEGIN
- menuBar := GetNewMBar(MBARID); { read menus into menu bar }
- IF menuBar = NIL THEN
- DeathAlert(rUtilStrings, eNoMenuBar);
- SetMenuBar(menuBar); { install menus }
- DisposeHandle(menuBar);
- AppendResMenu(GetMenuHandle(AppleMenuID), 'DRVR'); { add DA names to Apple menu }
- DrawMenuBar;
- END; { StandardMenuSetup }
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE ToggleCheck(dlgPtr: DialogPtr; chkItem: INTEGER);
-
- VAR
- iKind: INTEGER;
- iHandle: Handle;
- iRect: Rect;
- newValue: INTEGER;
-
- BEGIN
- GetDialogItem(dlgPtr, chkItem, iKind, iHandle, iRect);
- newValue := GetControlValue(ControlHandle(iHandle));
- IF newValue = 0 THEN
- newValue := 1
- ELSE
- newValue := 0;
- SetControlValue(ControlHandle(iHandle), newValue);
- END;
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilInit}
- FUNCTION TrapExists(theTrap: INTEGER): BOOLEAN;
-
- { Check to see if a given trap is implemented. This is only used by the
- Initialize routine in this program, so we put it in the Initialize segment. }
-
- VAR
- theTrapType: TrapType;
-
- BEGIN
- theTrapType := GetTrapType(theTrap);
- IF (theTrapType = ToolTrap) THEN BEGIN
- theTrap := BAND(theTrap, $07FF);
- IF theTrap >= NumToolboxTraps THEN
- theTrap := _Unimplemented;
- END;
-
- TrapExists := NGetTrapAddress(_Unimplemented, ToolTrap) <> NGetTrapAddress(theTrap,
- theTrapType);
- END; { TrapExists }
-
-
-
- {*****************************************************************************}
-
-
-
- {$S UtilMain}
- PROCEDURE ZoomToWindowDevice(window:WindowPtr; maxWidth,maxHeight,zoomDir:INTEGER; front:BOOLEAN);
-
- { Zoom the window to the size appropriate for the device that contains the
- most of the window. An additional feature is that you can state the
- maximum that a window should be zoomed, either horizontally or vertically.
- If you pass in a maximum of 0 for the zoom for either direction, then that
- direction will be zoomed to fit the device. }
-
- VAR
- oldPort: GrafPtr;
- contentRect, structureRect, deviceRect, newRect: Rect;
- width, height, dx, dy: INTEGER;
-
- BEGIN
- GetPort(oldPort);
- SetPort(window);
- EraseRect(window^.portRect); { Recommended for cosmetic reasons. }
-
- { If there is the possibility of multiple gDevices, then we must check them to
- make sure we are zooming onto the right display device when zooming out. }
-
- if (zoomDir = inZoomOut) and (gQDVersion > kQDOriginal) THEN BEGIN
-
- contentRect := GetWindowContentRect(window);
- structureRect := GetWindowStructureRect(window);
- deviceRect := GetWindowDeviceRectNMB(window);
-
- deviceRect.left := deviceRect.left + (contentRect.left - structureRect.left + 2);
- deviceRect.top := deviceRect.top + (contentRect.top - structureRect.top + 2);
- deviceRect.right := deviceRect.right - (structureRect.right - contentRect.right + 2);
- deviceRect.bottom := deviceRect.bottom - (structureRect.bottom - contentRect.bottom + 2);
- newRect := deviceRect;
-
- if maxWidth > 0 THEN BEGIN
- width := deviceRect.right - deviceRect.left;
- if width > maxWidth THEN BEGIN
- newRect.left := contentRect.left;
- newRect.right := newRect.left + maxWidth;
- END;
- END;
- if maxHeight > 0 THEN BEGIN
- height := deviceRect.bottom - deviceRect.top;
- if height > maxHeight THEN BEGIN
- newRect.top := contentRect.top;
- newRect.bottom := newRect.top + maxHeight;
- END;
- END;
- dx := deviceRect.left - newRect.left;
- if dx < 0 THEN BEGIN
- dx := deviceRect.right - newRect.right;
- if dx > 0 THEN
- dx := 0;
- END;
- dy := deviceRect.top - newRect.top;
- if dy < 0 THEN BEGIN
- dy := deviceRect.bottom - newRect.bottom;
- if dy > 0 THEN
- dy := 0;
- END;
- OffsetRect(newRect, dx, dy);
-
- WStateDataHandle(WindowPeek(window)^.dataHandle)^^.stdState := newRect;
- { Set up the WStateData record for this window. }
- END;
-
- ZoomWindow(window, zoomDir, front);
- SetPort(oldPort);
- END;
-
-
-